<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/4/7
  Time: 13:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
<%-- 声明脚本 --%>
  <%! //在这里面可以声明Java的代码 作用是给jsp翻译出来的Java类定义属性和方法等  %>
  <%!
    //声明属性
    private static int id;
    private static String name;
  %>

  <%!
    //声明静态代码块
    static {
      id = 10;
      name="jian";
    }
  %>

  <%!
    //声明类方法
    public void sleep(){
      System.out.println("jian");
    }
  %>

  <%!
    //生成内部类
    public abstract class A{

    }
  %>

<%-- 表达式脚本 --%>
<%--在JSP页面输出数据 所有的值都会以out.print()输出 且不能加分号结束 --%>
  <%= name %><%= "jainge" %>
  <%= request.getParameter("username") %>

<%-- 代码脚本 都会被翻译到_jspService方法内 --%>
  <%
    int i=0;
//  if (i==0){
//    response.setContentType("text/jsp;charset=utf-8");
//    PrintWriter writer = response.getWriter();
////    writer.write("建哥");
//    out.write("建哥");
//    response.getWriter().write("来");
//  }
  %>
<%
  for (int j = 1; j <=9; j++) {
    for (int k = 1; k <= j; k++) {%>

      <%=j +" * "+k+" = " + j*k%>
<% }
    %>
<%="<br>" %>
<%
  }
%>
<%
pageContext.setAttribute("key","pageContext");
  Set<Map.Entry<Object, Object>> entries = new HashMap<>().entrySet();
  for (Map.Entry<Object, Object> entry : entries) {
    Object key = entry.getKey();
  }
%>
  ${id}<br>
  ${empty username}<br>
  ${1/3}
  ${pageScope.key}
  ${pageContext.getAttribute("key")}
  ${pageContext.request.scheme}
  ${pageContext.request.serverName}
  ${pageContext.request.serverPort}
  ${pageContext.request.contextPath}
  ${pageContext.request.method}
  ${pageContext.request.remoteHost}
  ${pageContext.session.id}

  请求参数${param.get("name")}
  ${paramValues.hobby[0]}

  ${header["user-agent"]}
  ${headerValues["user-agent"][0]}

  ${cookie.JSESSIONID.name}
  ${cookie.JSESSIONID.value}

  获取context-param的参数值${initParam.username}

  <c:set scope="request" var="name" value="李子建">
<%--  可以往域内存数据 scope设置域 page表示pageCOntext （默认值）var 设置key value设置值  --%>
  </c:set>
<c:set scope="page" var="pass" value="123"/>
  ${requestScope.name}
  ${pageScope.pass}
<%--这里面的test属性表示判断条件 成立 标签体的内容就会显示  --%>
  <c:if test="${12 == 12}">
    <h1>12等于12</h1>
  </c:if>
  <c:set scope="page" var="height" value="170" />
<%-- choose开始判断 when表示每一种值 不需要手动break 注意在choose里不要有html注释 when标签的父标签一定要是choose标签 --%>
  <c:choose>
    <c:when test="${pageScope.height > 160}">
      <h1>巨人</h1>
    </c:when>
    <c:when test="${pageScope.height > 165}">
      <h1>大巨人</h1>
    </c:when>
    <c:otherwise>巨巨人</c:otherwise>
  </c:choose>

<%-- begin设置开始的索引  end设置结束的索引  var属性表示循环的变量 包含其实位置和结束位置 --%>
  <c:forEach begin="1" end="10" var="i">
      ${i}
  </c:forEach>

<%--  --%>
<%
request.setAttribute("arr",new String[]{"李子建","最帅"});
%>
  <c:forEach items="${requestScope.arr}" var="item">
      ${item}<br>
  </c:forEach>

<%-- Map遍历 --%>
  <%
    Map<String,Object> map = new HashMap<>();
    map.put("name","李子建");
    map.put("age",18);
    map.put("sex","男");
        request.setAttribute("map",map);
  %>

  <c:forEach begin="1" end="2" items="${requestScope.map}" var="entry">
      ${entry.key} ${entry.value}<br>
  </c:forEach>
${}
<form action="http://localhost:8080/ge" method="post" enctype="multipart/form-data">
    <input type="file" name="image">
    <button type="submit">提交</button>
</form>
  </body>
</html>
